package com.zl.customer.web;


import com.zl.customer.pojo.Customer;
import com.zl.customer.service.CustomerService;
import com.zl.customer.service.impl.CustomerServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author suke
 * @create 2021-07-07 10:28
 */
@WebServlet(name = "QueryAllServlet",urlPatterns = "/QueryAllServlet.action")
public class QueryAllServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.设置编码
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        //2.业务逻辑代码
       /* CutsomerDao customerDao  = new CustomerDaoImpl();*/
        CustomerService  customerService = new CustomerServiceImpl();

        //3.调用方法
     /*  List<Customer> list =  customerDao.queryAll();*/
        List<Customer> list =  customerService.queryAll();
       //把数据保存在request域
        request.setAttribute("customers",list);

        //4.转发到list.jsp  使用绝对路径
        request.getRequestDispatcher("/jsp/list.jsp").forward(request,response);
        // 注意:  转发中的url:   不要加/项目名    /url路径
        //       重定向的url:   加/项目名        /项目名/url路径
        //      前端页面中的url:   /项目名/url

    }
}
